//导入 createSlice
import { createSlice } from "@reduxjs/toolkit";

//创建 slice 对象
let collSlice = createSlice({
  name: 'collection',
  initialState: 
  {
    value: 0,
    test: 100
  },
  reducers: {
    //新增
    incre: (state, action) => {
      //看上去是在对内部的状态进行修改, 其实底层还是创建副本进行了更新
      state.value += 1;
      //返回新值的方式也是可以的
      // return {
      //   value: state.value + 2
      // }
    },
    decre: (state, action) => {
      state.value -= 1;
    }
  }
});

//暴露
export let {incre, decre} = collSlice.actions;

//暴露 reducer
export default collSlice.reducer;